import autoit


class MouseControl(object):
    '''
    AutoIt鼠标相关操作
    '''

    def __init__(self):
        pass

    def click(self, title, text, x, y, button="main", clicks=1):
        '''
        执行鼠标点击操作

        :Args:
         - title: 窗口标题
         - text: 窗口文本
         - x: 窗口内的横坐标
         - y: 窗口内的纵坐标
         - button: 鼠标按键，默认为'main'
         - clicks: 按键次数，默认为1

        :Usage:
            mouse.click('文件上传','',100,100,'main',1)
        '''
        pos = autoit.win_get_pos(title, text=text)
        autoit.mouse_click(button, x + pos[0], y + pos[1], clicks=clicks)

    def move(self, title, text, x, y):
        '''
        移动鼠标指针

        :Args:
         - title: 窗口标题
         - text: 窗口文本
         - x: 窗口内的横坐标
         - y: 窗口内的纵坐标

        :Usage:
            mouse.move('文件上传','',100,100)
        '''
        pos = autoit.win_get_pos(title, text=text)
        autoit.mouse_move(x + pos[0], y + pos[1])

    def drag(self, title, text, x1, y1, x2, y2):
        '''
        执行鼠标拖拽操作

        :Args:
         - title: 窗口标题
         - text: 窗口文本
         - x1: 窗口内开始移动的横坐标
         - y1: 窗口内开始移动的纵坐标
         - x2: 窗口内结束移动的横坐标
         - y2: 窗口内结束移动的纵坐标

        :Example:
         - 例: mouse.drag('文件上传','',100,100,200,200)
        '''
        pos = autoit.win_get_pos(title, text=text)
        autoit.mouse_click_drag(x1 + pos[0], y1 + pos[1], x2 + pos[0], y2 + pos[1])

    def wheel(self, direction="up"):
        '''
        产生向上或向下滚动鼠标滚轮事件.仅支持NT/2000/XP及更高.

        :Args:
         - direction: 鼠标滚轮滚动方向，默认是up

        :Example:
         - 例: mouse.wheel('down')
        '''
        autoit.mouse_wheel(direction)